<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>{$appConfigs.title}</title>
    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/easyui/themes/{$page_theme | default: 'default'}/easyui.css">
    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/easyui/themes/color.css">
    <link rel="stylesheet" type="text/css" href="{$contextPath}/pas/editor/themes/default/default.css" />
    
    <script type="text/javascript" src="{$contextPath}/pas/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="{$contextPath}/pas/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="{$contextPath}/pas/easyui/jquery.easyui.patch.js"></script>
    <script type="text/javascript" src="{$contextPath}/pas/editor/kindeditor-min.js"></script>
    <script type="text/javascript" src="{$contextPath}/pas/editor/lang/zh_CN.js"></script>
</head> 
<body onpageshow="resetPagination()">
    <table id="dg" title="发布信息" class="easyui-datagrid" style="width:99%;height:95%"
            url="{$contextPath}/cms/content/findByCategoryId2.xdo?category_id={$Request.category_id}"
            toolbar="#toolbar" pagination="true" pageSize="15" pageList="[15,30]"
            rownumbers="true" fitColumns="true" singleSelect="false">
        <thead>
            <tr>
                <th field="category_name" width="40">栏目</th>
                <th field="icon" width="15" formatter="iconFormatter">ICON</th>
                <th field="title" width="100">标题</th>
                <th field="tag" width="50">标签</th>
                <th field="sort_id" width="30" align="right">排序</th>
                <th field="status" width="30" data-options="formatter:{literal}function(v){return v=='1'?'已发布':'<font color=red>未发布</font>'}{/literal}">状态</th>
                <th field="publish_date" width="30">发布时间</th>
                <th field="create_date" width="30">创建时间</th>
                <th field="content_id" width="11" formatter="opFormatter">操作</th>
            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="createOne()">新建</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="updateOne()">修改</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-man" plain="true" onclick="publishOne()">发布</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-man" plain="true" onclick="unpublishOne()">取消发布</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeOne()">删除</a>
        <span style="width:50px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
        <input id="words" name="words" class="easyui-textbox" style="width:150px" maxlength='20'>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearch()">搜索</a>
    </div>
    <div id="dlg" class="easyui-dialog" style="width:1000px; height:600px;padding:10px 20px"
            closed="true" buttons="#dlg-buttons">
        <div class="ftitle">信息</div>
        <form id="fm" method="post" enctype="multipart/form-data" novalidate>
            <div class="fitem">
                <label>栏目:</label>
				<select name="category_id" id="category_id" class="easyui-combotree" style="width:500px;"
						data-options="url:'{$contextPath}/cms/category/findChildrenTree.xdo?parent_id={$Request.pid|default:'0'}&category_id={$category_id}',required:true, editable:false">
				</select>
            </div>
            <div class="fitem">
                <label>标题:</label>
                <input id="title" name="title" class="easyui-textbox" required="true" style="width:500px" maxlength='20'>
            </div>
            <div class="fitem">
                <label>标签:</label>
                <input id="tag" name="tag"  class="easyui-textbox" style="width:500px">
            </div>
            <div class="fitem">
                <label>ICON:</label>
                <input id="icon" name="icon" type="file" style="width:500px">
            </div>
            <div class="fitem">
                <label>排序:</label>
                <input id="sort_id" name="sort_id" class="easyui-numberbox" value="0">
                <label>&nbsp;</label>
                <label>发布时间:</label>
                <input id="publish_date" name="publish_date" class="easyui-datetimebox">
            </div>
            <div class="fitem">
                <label>摘要:</label>
                <textarea id="summary" name="summary" class="easyui-validatebox" style="height:40px;width:500px"></textarea>
            </div>
            <div class="fitem">
                <label>内容:</label>
		        <textarea id="content" name="content" cols="250" rows="8" class="txtContent"
		            style="width: 90%; height: 470px; visibility: hidden;"></textarea>
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveOne()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
    <div style="position: fixed; z-index: 10000; top: 0; left: 0; right: 0; bottom: 0; height: 100%; background-color: rgba(0, 0, 0, .3); display:none;" id="js-waiting">
        <img style="position: absolute; z-index: 1000; width: 80px; height 80px; left: 50%; top: 50%; margin-left: -40px; margin-top: -40px;" src="http://yun.zy.com:9090/cms/easyui/themes/default/images/loading.gif"/>
    </div>
    <script type="text/javascript">
    var category_id = '{$Request.category_id}';
    var uploadURL = '/uploads';
    {literal}
        var url;
        function createOne(){
            $('#dlg').dialog('open').dialog('setTitle','新增');
            $('#fm').form('clear');
			editor.html("");
			url = '/cms/content/create.xdo';
			var row = {};
			row.category_id=category_id;
			$('#fm').form('load',row);
        }
        function updateOne(){
            var row = $('#dg').datagrid('getSelected');
            $('#fm').form('clear');
            if (row){
                $('#dlg').dialog('open').dialog('setTitle','修改');
                row['icon']=null;
                row['icon2']=null;
                row['icon3']=null;
                row['icon4']=null;
		row['f9']=null;
                $('#fm').form('load',row);
				editor.html(row.content);
				url = '/cms/content/update.xdo?content_id='+row.content_id;
            }
        }
        function saveOne(){
            if(document.getElementById("title").value.length > 200){
        		$.messager.show({
                            title: 'Error',
                            msg: '标题超过200个字符'
                        });
        		return;
        	}
        	if(document.getElementById("sort_id").value.length > 10){
        		$.messager.show({
                            title: 'Error',
                            msg: '排序超过10位'
                        });
        		return;
        	}

            $('#js-waiting').show();
            $('#fm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){
                    var result = eval('('+result+')');
                    $('#js-waiting').hide();
                    if (result.ReturnCode != 0){
                        $.messager.show({
                            title: 'Error',
                            msg: result.Msg
                        });
                    } else {
                        $('#dlg').dialog('close');        // close the dialog
                        $('#dg').datagrid('reload');    // reload the user data
						$('#parent_id').combotree('reload');
                    }
                }
            });
        }
        function removeOne(){
            var selections = $('#dg').datagrid('getSelections');
            if (selections.length > 0 ){
            	var rows = new Array();
            	for(var i=0; i< selections.length; i++){
            		rows.push(selections[i].content_id);
            	}
                $.messager.confirm('Confirm','删除后数据不能恢复，确认删除么?',function(r){
                    if (r){
                        $.post('/cms/content/remove.xdo',{content_id:rows},function(result){
                            if (result.ReturnCode == 0){
                                $('#dg').datagrid('reload');    // reload the user data
								$('#parent_id').combotree('reload');
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.Msg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
        function publishOne(){
            var selections = $('#dg').datagrid('getSelections');
            if (selections.length > 0 ){
            	var rows = new Array();
            	for(var i=0; i< selections.length; i++){
            		rows.push(selections[i].content_id);
            	}
                $.messager.confirm('Confirm','发布后，其他系统将可以查到此数据，确认发布么?',function(r){
                    if (r){
                        $.post('/cms/content/publish.xdo',{content_id:rows},function(result){
                            if (result.ReturnCode == 0){
                                $('#dg').datagrid('reload');    // reload the user data
								$('#parent_id').combotree('reload');
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.Msg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
        function unpublishOne(){
            var selections = $('#dg').datagrid('getSelections');
            if (selections.length > 0 ){
            	var rows = new Array();
            	for(var i=0; i< selections.length; i++){
            		rows.push(selections[i].content_id);
            	}
                $.messager.confirm('Confirm','确认取消发布么?',function(r){
                    if (r){
                        $.post('/cms/content/unpublish.xdo',{content_id:rows},function(result){
                            if (result.ReturnCode == 0){
                                $('#dg').datagrid('reload');    // reload the user data
								$('#parent_id').combotree('reload');
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.Msg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
        function doSearch() {
        	var words=$('#words').val();
        	$('#dg').datagrid('reload',{"words":words});
        }
		function iconFormatter(value, row, index){
			if(!row.icon || row.icon == '' || row.icon == 'null') return "-";
			return '<img height=40 width=40 src=\"' + uploadURL + "/" + row.icon+'\">';
		}
		function opFormatter(value, row, index){
			if(!value) value ="";
			return '<a target=\"_blank\" href=\"preview.shtml?content_id='+row.content_id+'\" >预览</a>';
		}
		function resetPagination(){
			var p = $('#dg').datagrid('getPager');
			$(p).pagination({             
				pageSize: 15,           
		 		pageList: [15,30],
				beforePageText: '第',      
				afterPageText: '页    共 {pages} 页',             
				displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'                  
			}); 
		}
    </script>
    <script type="text/javascript">
        //编辑器
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="content"]', {
                allowFileManager: false,
                resizeType: 1,
                allowPreviewEmoticons: false,
                items: [
                    'preview', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                    'insertunorderedlist', 'quickformat', '|', 'emoticons', 'image', 'flash', 'media', 'link','pagebreak','|', 'fullscreen','source'],
                afterChange: function () {
                    this.sync();
                }
            });
        });
        $(document).ready(function(){
        	//$('#category_id').combobox("setValue", '19');
        	//$('#category_id').combobox("select", '19');
        });
    </script>
    <style type="text/css">
        #fm{
            margin:0;
            padding:10px 30px;
        }
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:80px;
        }
        .fitem input{
            width:160px;
        }
    </style>
    {/literal}
</body>
</html>